package cn.befory.controller;

import cn.befory.pojo.User;
import cn.befory.service.UserService;
import cn.befory.tools.ResponseContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by befory on 2019/9/22.
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

//    @GetMapping("/index")
//    public ModelAndView index(){
//        ModelAndView mv = new ModelAndView();
//        mv.setViewName("user/index");
//        return mv;
//    }
//
//    @GetMapping("/toAdd")
//    public ModelAndView toAdd(){
//        ModelAndView mv = new ModelAndView();
//        mv.setViewName("user/add");
//        return mv;
//    }

    @GetMapping("/page/{pageNo}/{pageSize}")
    public ResponseEntity page(User user, @PathVariable Integer pageNo, @PathVariable Integer pageSize) throws Exception{
        return ResponseEntity.ok(ResponseContent.success(userService.page(user,pageNo,pageSize)));
    }

    @PostMapping("/add")
    public ResponseEntity add(User user) throws Exception{
        return ResponseEntity.ok(ResponseContent.success(userService.add(user)));
    }


}
